import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import './assets/base.scss'
import '@/assets/icon/iconfont.css'

import Table from "@/components/Table.vue"
import Dialog from "@/components/Dialog.vue"
import Cover from "@/components/Cover.vue"
import SunEditor from "@/components/SunEditor.vue"

import CategorySelect from "@/components/content/CategorySelect.vue"

import Request from './utils/Request'
import Message from './utils/Message'
import VueCookies from "vue-cookies"
import Confirm from "@/utils/Confirm.js";
import PermissionCode from "@/utils/PermissionCode.js";

const app = createApp(App)

app.use(router)
app.use(ElementPlus)

app.component("Table",Table)
app.component("Dialog",Dialog)
app.component("Cover",Cover)
app.component("SunEditor",SunEditor)

app.component("CategorySelect",CategorySelect)

app.config.globalProperties.Request = Request;
app.config.globalProperties.Message = Message;
app.config.globalProperties.Confirm = Confirm;
app.config.globalProperties.VueCookies = VueCookies;
app.config.globalProperties.PermissionCode = PermissionCode;
app.config.globalProperties.globalInfo = {
    avatarUrl:"/api/file/getAvatar/",
    imageUrl: "/api/file/getImage/"
};

// 自定义属性
app.directive('has',{
    mounted:(el,binding,vnode)=>{
        let userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
        let permissionCodeList = userInfo.permissionCodeList;
        permissionCodeList = permissionCodeList == undefined ? [] : permissionCodeList;
        if(!permissionCodeList.includes(binding.value)){
            el.parentNode.removeChild(el);
        }
    }
})

app.mount('#app')
